﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LiteBlog.IoC;
using LiteBlog.Repositories.Contracts;
using Moq;
using System.IO;
using System.Xml.Linq;
using LiteBlog.Repositories.Common;

namespace LiteBlog.Repositories.Tests
{
    [TestClass]
    public abstract class RepositoryTests<T> 
        where T: IRepository
    {
        protected T _repository;
        protected Mock<IXmlHelper> _mock;
        protected XElement _root;

        [TestInitialize]
        public void InitTest()
        {
            _repository = IoCContainer.Resolve<T>();
            _mock = Mock.Get<IXmlHelper>(_repository.XmlHelper);
            SetupLoad();
        }

        [TestMethod]
        public void ComponentIsNotNull()
        {
            Assert.IsNotNull(_repository);
        }

        [TestMethod]
        public virtual void PathIsCorrect()
        {
            Assert.IsTrue(VerifyPath(_repository.Path));
        }

        protected bool VerifyPath(string path)
        {
            string expectedPath = Path.Combine(AssemblySetup.DataPath, GetFileName());
            return expectedPath.Equals(path);
        }

        protected abstract void SetupLoad();
        protected abstract string GetFileName();
    }
}
